Network layer(二)协议
Intro
大致的协议:
Internet protocol
Packet
IP address
Other protocol
Arp
Dhcp
Rarp
ICMP
CIDR
设计issue for Internet
Design Principles for Internet (RFC 1958)
1.Make sure it works.
2.Keep it simple.
3.Make clear choices.
4.Exploit modularity.
5.Expect heterogeneity.
6.Avoid static options and parameters.
7.Look for a good design; it need not be perfect.
8.Be strict when sending and tolerant when receiving.
9.Think about scalability.
10.Consider performance and cost.
关于IP
整个网络可以被看成多个子系统,需要glue粘结他们,IP就是这样的
作用就是提供一个最佳的路径,但是不保证最佳的路径一定能找到
基础概念
Def of IP address:IP地址被用来给Internet上的电脑一个编号。大家日常见到的情况是每台联网的PC上都需要有IP地址,才能正常通信。我们可以把“个人电脑”比作“一台电话”,那么“IP地址”就相当于“电话号码”,而Internet中的路由器,就相当于电信局的“程控式交换机”。(可以理解为身份证)
Def of 网关(gateway):网关(Gateway)又称网间连接器、协议转换器。默认网关在网络层上以实现网络互连,是最复杂的网络互连设备,仅用于两个高层协议不同的网络互连。网关的结构也和路由器类似,不同的是互连层。网关既可以用于广域网互连,也可以用于局域网互连。网关实质上是一个网络通向其他网络的IP地址。
路由器和网关的区别:
Def of 子网掩码(subnet mask):子网掩码 (subnet mask) 又叫网络掩码、地址掩码、子网络遮罩,是一个应用于 TCP/IP 网络的 32 位二进制值。它可以屏蔽掉 IP 地址中的一部分,从而分离出 IP 地址中的网络部分与主机部分,基于子网掩码,管理员可以将网络进一步划分为若干子网。它必须结合 IP 地址一起使用
例子:
广播与单播:广播大致与单播消息相反,单播是从一台主机到另一台主机的通信,单播有时被称为一对一通信,而广播可以被认为是一对多通信
Addressing:
Def of Addressing:目的是共享资源,与远端节点通信,要做到这一点,首先必须要找到目的节点,寻找目的节点的过程是寻址
两类addressing:
MAC addressing: 通过MAC address 定位目的地
IP addressing: 通过IP address 寻址
IP Addressing
步骤:
1.packet到达 一个router
2.The router forward the packet
3. Locate the destination
Def:IP地址是IP协议提供的一种统一的地址格式,它为互联网上的每一个网络和每一台主机分配一个逻辑地址,以此来屏蔽物理地址的差异
后面会具体介绍IP Address
Router
Process of router:
open packet
Decide destination network
Look up routing-table,re-encapsulation and forward
router主要功能
routing
Forward
other
Routing table:
内容:网络地址,接口,metric,subnet mask,gateway等
除了连接设备的IP和MAC地址,router还有她的邻居router的IP和MAC地址(APR table)
因为不同的因素影响,可能有些不同
Internet protocal
Internet protocol
Packet format
Addressing
IP packet format
结构:
各成分的内容:
版本号:4bits 识别用的是哪个版本:IPV6(0110)还是IPV4(0100)
IHL: 长度为4bits。IP head length(IP分组的头部是可变的),由于头的长度不固定,所以头的 IHL 宇段指明了头到底有多长(以 32 位字长度为单位),最小是5。
Type of service(TOS):8 bits ,来区分不同的服务种类。可靠性和速度的各种组合都是可能的选择
Total length:16bits 单位是字节,包含了该数据报中的所有内容,即头和数据。最大长度是65 535 (2^16次)个字节
Identification:16bits,的用途是让目标主机确定一个新到达的分段属于哪一个数据报
DF和MF:标记字段(Flag)——长度为3位,其中第1位没有使用。第2位是不分段(DF)位。当DF位被设置为1时,表示路由器不能对数据包进行分段处理。如果数据包由于不能被分段而未能被转发,那么路由器将丢弃该数据包并向源点发送错误消息。dont fragment 和 more fragment。
Fragment offest:13bits,用于指明分段起始点相对于报头起始点的偏移量,如果有错误,必须重头开始发送
Time to live(TTL):8 bits 跳数,每次跳都会减一
Protocol:8bits 承载的数据是用什么协议处理的
Header checksum:校验和,是针对IP报头的纠错字段。校验和不计算被封装的数据,UDP、TCP和ICMP都有各自的校验和。
source address:32 bit 分别表示发送者数据包源点
destination address:32 bits 分别表示目的地的IP地址
options:是一个长度可变的字段,并像其名字所表示的,它是可选的。可选项被添加在包头中,包括源点产生的信息和其他路由器加入的信息允许IP支持多种多样的不同优化比如安全性,错误报告,router等
IP Address
格式:分为 network number和host number
长度是32bits 如果是2进制的话非常难记忆
解决办法:可以用10进制加小数点来记忆,32bits 分成4个8bits 每8bits之间用.分开,每个的范围是0-255
IP地址的结构是采用分层结构,在同一层里面的前面都一样,后面不一样
IP 地址的分类
IP地址分为ABCDE五类,这五类不同在于他们前面的前缀不同
以下所有计算子网都减去了2是因为:减2是因为主机不包括网络地址和广播地址
A类
特点:
1.The first byte is identified to network,the last three bytes are identified to host
2.Each net can include (224 -2)host at most
3.The highest bit is “0”
4.The first byte range “0-127” , so number of net is 128
B类
特点:
1.The first two bytes are network bits, the last two bytes are host bits.
2.Each net can include(216-2)host at most
3.The highest two bits are “10”
4.The first byte range “128-191”
5.Number of net is 214
C类
特点:
1.The first three bytes are network bits, the last byte is host bits
2.Each net can include 254 host at most
3.The highest three bits are“110”
4.The first byte range “192-223”
5.number of net is 221
Special IP address
32 bit all 0,0.0.0.0 Cisco default routing
32 all 1,255.255.255.255 Flood Broadcast
Host id all 0,network address 172.16.0.0
Host id all 1,172.16.255.255 Direct Broadcast
127.0.0.0 Lookback Network
127.0.0.1 Lookback test
Flood Broadcast
对于用作第 3 层广播的目标 IP 地址的内容,有两种不同的选择。
这两个选项是Local Broadcast和Directed Broadcast(有时也称为Targeted Broadcast)。
广播和单播定义见前面
Flood Broadcast = Local Broadcast
32 all 1,255.255.255.255
无论特定主机位于何种 IP 网络上,该主机始终可以使用该 IP 地址向本地网络上的每个节点发送数据包。
Direct Broadcast
定向广播 IP 地址就是所谓的每个子网的广播 IP,要找到这个 IP 地址,您必须进行一些子网划分。v
Public and private address
一种分类就是公网和私网IP地址
Def of Private IP Address:The Private IP Address of a system is the IP address that is used to communicate within the same network.
Def of Public IP Address:The Public IP Address of a system is the IP address that is used to communicate outside the network.
Subnet(子网)
背景:A LAN may grow to be too large to handle and must be split into subnets.
功能:
1.Subsets allow a network to be split into several parts for internal use but still act like a single network (i.e., a single routing table entry) to the outside world.
2.This allows different subnets to be connected within an organization.
Subnet mask
功能:A mask is used by the router to determine which subnet the packet should travel to.
子网掩码不能单独存在,它必须结合IP地址一起使用。IP地址我们都知道是计算机在网络内的唯一标识,而子网掩码顾名思义是用于划分子网的
子网掩码是一个32位地址,用于屏蔽IP地址的一部分以区别网络标识和主机标识,并说明该IP地址是在局域网上,还是在远程网上。
subnet的指定:Subnet masks can be specified in dotted decimal notation, with the addition of a slash followed by the number of bits in the network + subnet part.
Routers will AND the destination address with the subnet mask in order to get the address of the router where the packet should go.
Using this method reduces the number of individual addresses that each router must store, resulting in smaller router tables.
Default subnet mask
A:255.0.0.0
B:255.255.0.0
C:255.255.255.0
例子
划分规则:
Subnetting
子网划分
dEF:Subnetting is the process of creating a subnetwork (also known as a subnet) within a network.
A subnet contains three main elements:
1.Network address (or) subnet ID: This is always the first address of the subnet.
3.Broadcast address: This is always the last address of the subnet. A packet forwarded to the broadcast address is broadcasted to all the addresses in a subnet.
3.Subnet mask (or) netmask: This is the bitmask used to identify the subnet of an IP address by applying bitwise AND operation with the netmask and the IP address. All the IP addresses in a subnet contain an identical most-significant bit group. This is how a router identifies the subnet of an IP address since data packets only contain the destination IP address.
32位2进制数字,1表示网络号,0是主机号或者网络后缀法表示子网掩码
划分后,源网络号不变,但是主机号变成子网号加主机号
第一步:确定借几位host number
要保证,可表示的子网个数大于我们所需要的,然后每个子网可分配给主机的IP数 大于等于50
第二步:确定每个子网子网掩码
第三部:确定子网的网络地址(网络号不变,主机号全0)
- Title: Network layer(二)协议
- Author: 杨小鹤
- Created at: 2023-11-04 10:55:32
- Updated at: 2023-11-05 18:38:53
- Link: https://redefine.ohevan.com/2023/11/04/CN11/
- License: This work is licensed under CC BY-NC-SA 4.0.